/***************************************************************************
 * 文件名：ReferenceModel
 * 功能：
 * 说明：
 * -------------------------------------------------------------------------
 * 创建时间：2025/7/14 10:48:19
 * 创建人：葛浩
 * 邮箱： 2094733071@qq.com
 * =========================================================================
 *
 * 修改人：   
 * 修改时间：   
 * 修改说明：   
 ***************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BuiltInTools
{
	/// <summary>
	/// 程序集引用模型
	/// </summary>
	public class AssemblyReferenceModel : ReferenceBaseEntity
	{
		/// <summary>
		/// 程序集名称
		/// </summary>
		public string AssemblyReferenceName { get; set; }

		/// <summary>
		/// 相对路径
		/// </summary>
		public string RelativePath { get; set; }

		/// <summary>
		/// 依赖的目标框架
		/// </summary>
		public string RequiredTargetFramework { get; set; }

		/// <summary>
		/// 版本号
		/// </summary>
		public bool? SpecificVersion { get; set; }

		public override string ToString()
		{
			return string.Join(", ", new string[]
			{
						$"{nameof(AssemblyReferenceName)}:{AssemblyReferenceName}",
						$"{(string.IsNullOrEmpty(RelativePath) ? "" : $"{nameof(RelativePath)}:{RelativePath}")}",
						$"{(string.IsNullOrEmpty(RequiredTargetFramework) ? "" : $"{nameof(RequiredTargetFramework)}:{RequiredTargetFramework}")}",
						$"{(!SpecificVersion.HasValue ? "" : $"{nameof(SpecificVersion)}:{SpecificVersion}")}",
			}.Where(p => !string.IsNullOrEmpty(p)));
		}
	}

	/// <summary>
	/// 项目引用模型
	/// </summary>
	public class ProjectReferenceModel : ReferenceBaseEntity
	{
		/// <summary>
		/// 引用名称
		/// </summary>
		public string ProjectReferneceName { get; set; }

		/// <summary>
		/// 相对路径
		/// </summary>
		public string RelativePath { get; set; }

		/// <summary>
		/// 全路径名称
		/// </summary>
		public string FullName { get; set; }

		/// <summary>
		/// 引用项目名称
		/// </summary>
		public string Project { get; set; }

		public override string ToString()
		{
			return string.Join(", ", new string[]
			{
						$"{nameof(ProjectReferneceName)}:{ProjectReferneceName}",
						$"{(string.IsNullOrEmpty(RelativePath) ? "" : $"{nameof(RelativePath)}:{RelativePath}")}",
						$"{(string.IsNullOrEmpty(FullName) ? "" : $"{nameof(FullName)}:{FullName}")}",
						$"{(string.IsNullOrEmpty(Project) ? "" : $"{nameof(Project)}:{Project}")}",
			}.Where(p => !string.IsNullOrEmpty(p)));
		}
	}

	/// <summary>
	/// 包引用
	/// </summary>
	public class PackageReferenceModel : ReferenceBaseEntity
	{
		/// <summary>
		/// 包名称
		/// </summary>
		public string PackageReferenceName { get; set; }

		/// <summary>
		/// 版本信息类型（""：无，OverrideVersion:覆盖版本（与中央包管理版本不同）, Version）
		/// </summary>
		public string VersionType { get; set; }

		/// <summary>
		/// 版本号
		/// </summary>
		public string Version { get; set; }

		public override string ToString()
		{
			return string.Join(", ", new string[]
			{
						$"{nameof(PackageReferenceName)}:{PackageReferenceName}",
						$"{(string.IsNullOrEmpty(VersionType) ? "" : $"{nameof(VersionType)}:{VersionType}")}",
						$"{(string.IsNullOrEmpty(Version) ? "" : $"{nameof(Version)}:{Version}")}",
			}.Where(p => !string.IsNullOrEmpty(p)));
		}
	}

	/// <summary>
	/// 所有引用名称
	/// </summary>
	public class AllReferenceModel : ReferenceBaseEntity
	{
		/// <summary>
		/// 引用名称
		/// </summary>
		public string ReferenceName { get; set; }

		/// <summary>
		/// 引用类型
		/// </summary>
		public string ReferenceType { get; set; }

		/// <summary>
		/// 相对路径
		/// </summary>
		public string RelativePath { get; set; }

		/// <summary>
		/// 引用项目名称
		/// </summary>
		public string Project { get; set; }

		/// <summary>
		/// 版本号
		/// </summary>
		public bool? SpecificVersion { get; set; }

		/// <summary>
		/// 版本信息类型（""：无，OverrideVersion:覆盖版本（与中央包管理版本不同）, Version）
		/// </summary>
		public string VersionType { get; set; }

		/// <summary>
		/// 版本号
		/// </summary>
		public string Version { get; set; }
	}

	/// <summary>
	/// 引用Model类
	/// </summary>
	public class ReferenceModel
	{
		public string SolutinPath { get; set; }

		public string ProjectPath { get; set; }

		/// <summary>
		/// 所有引用
		/// </summary>
		public List<AllReferenceModel> AllReferenceList { get; set; }

		/// <summary>
		/// 程序集引用列表
		/// </summary>
		public List<AssemblyReferenceModel> AssemblyList { get; set; }

		/// <summary>
		/// 项目引用列表
		/// </summary>
		public List<ProjectReferenceModel> ProjectList { get; set; }

		/// <summary>
		/// 包引用列表
		/// </summary>
		public List<PackageReferenceModel> PackageList { get; set; }

		/// <summary>
		/// 背景颜色
		/// </summary>
		public string BackColor { get; set; }

		/// <summary>
		/// 字体颜色
		/// </summary>
		public string ForeColor { get; set; }


		public override string ToString()
		{
			var preStr = string.Empty;
			if (!string.IsNullOrWhiteSpace(this.SolutinPath))
			{
				preStr += $"解决方案：{this.SolutinPath}\t";
			}
			if (!string.IsNullOrWhiteSpace(this.ProjectPath))
			{
				preStr += $"项目：{this.ProjectPath}\t";
			}

			if ((AssemblyList?.Count == 0) && (ProjectList?.Count == 0) && (PackageList?.Count == 0))
			{
				return $"{preStr}未查询到符合条件的引用";
			}

			var resultBuilder = new StringBuilder();
			return string.Join(Environment.NewLine,
				(this.AssemblyList?.Select(p => $"{preStr} 程序集引用：{p.ToString()}")?.ToList() ?? new List<string>(0))
				.Concat((this.ProjectList?.Select(p => $"{preStr} 项目引用：{p.ToString()}")?.ToList() ?? new List<string>(0)))
				.Concat((this.PackageList?.Select(p => $"{preStr} 包引用：{p.ToString()}")?.ToList() ?? new List<string>(0))));
		}
	}

	/// <summary>
	/// 引用基类
	/// </summary>
	public class ReferenceBaseEntity
	{
		/// <summary>
		/// 所属项目
		/// </summary>
		public string ProjectName { get; set; }

		/// <summary>
		/// 项目文件名称
		/// </summary>
		public string ProjectFileName { get; set; }
	}
}
